package 力扣._19_删除第倒数K个;
import 力扣.公用数据结构.ListNode;

public class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode node = new ListNode();
        node.next = head;   //补上头结点
        ListNode pre_k = node, p_k = node.next, p_t = node.next;
        while (p_t != null) {   //
            p_t = p_t.next;
            if (n > 0)
                n--;
            else {
                pre_k = p_k;
                p_k = p_k.next;
            }
        }
        if (p_k != null) {
            pre_k.next = p_k.next;
        }
        return node.next;
    }
}
